package com.bipa.dao;

import com.bipa.bean.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserDao {

    //根据登录名或邮箱，密码查询用户
    @Select("SELECT * FROM ec_user  where PASSWORD = #{psw} AND LOGIN_NAME = #{account} OR EMAIL = #{account}")
    public User findByAccountOrPsw(@Param("account") String account, @Param("psw") String psw);

    @Select("select * from ec_user where id = #{id}")
    public User findById(@Param("id")Integer id);

    @Insert("insert into ec_user(login_name,password,name,sex,email,phone,address,create_date,active)  " +
            "values(#{login_name},#{password},#{name},#{sex},#{email},#{phone},#{address},#{create_date},#{active})")
    public int register(User user);

    @Update("update ec_user set disabled = '1' where active = #{activeCode}")
    void activeUser(String activeCode);

    @Select("select * from ec_user where role = 2")
    public List<User> getAllManageUser();

    @Update("update ec_user set name = #{name},email = #{email},phone = #{phone},address = #{address} where id = #{id}")
    public void update(User user);

}
